from django.shortcuts import render
from .settings import *
import requests
# Create your views here.
def asser_buyer(request):
    """
                @author:薛威宁
                @date:2018/10/20/
                提交方式 ：POST
                提交数据格式 ：{提交数据库格式:{"asset_name"："xxx","pur_name"："x",user"："xx","save_room"："仓库"}
    仓库格式:{'asset_name':'xxx','room':'xxx','asset_num':'数字'}
            """
    if request.method == 'POST':
        info = dict(request.POST)
        print(info)
        url_ip = url + 'asset/asser_buyer/'
        r = requests.post(url_ip, data=info)
        print(r.text)
        rt = r.text
        if rt == '资产已入库':
            context = {'message':rt}
            return render(request, 'apiasset/asset_by.html',context)
        else:
            context = {'message': '购买成功'}
            return render(request, 'apiasset/asset_by.html',context)
    elif request.method == 'GET':
        return render(request, 'apiasset/asset_by.html')


def asset_receive(request):
    """

    资产领用
    @account:韩松
    @time:2018/10/21
    提交方式:post
    提交数据库格式: 领用格式:{'tower_id':['楼名'],'tier_id':['层号'],'tier_id001':['房间'],'tower_name':['物品名称'], 'tower_num':['数量'], 'tower_id1':['楼名'], 'tier_id2':['层号'],
    'tier_id3':['房间号'],'put_name':['提交人名'],}
    """
    if request.method == 'POST':
        info = dict(request.POST)
        print(info)
        url_ip = url + 'asset/asset_receive/'
        r = requests.post(url_ip, data =
{
            'tower_id':info['tower_id'],
            'tier_id':info['tier_id'],
            'tier_id001':info['tier_id001'],
            'tower_name': info['tower_name'],
            'tower_num': info['tower_num'],
            'tower_id1': info['tower_id1'],
            'tier_id2': info['tier_id2'],
            'tier_id3': info['tier_id3'],
            'put_name': info['put_name1'],
            }
                          )
        print(r.text)

        rt = r.text
        if rt == '转移成功':
            context = {'message':rt}
            return render(request, 'apiasset/receive.html',context)
        else:
            context = {'message':rt}
            return render(request, 'apiasset/receive.html',context)
    elif request.method == 'GET':
        return render(request, 'apiasset/receive.html')
